<?php    
	$name    = $_POST['name']; 
   	$opercode   = $_POST['opercode'];

	set_time_limit(0);  
    $host="localhost";  
    $port=9734;  
      
    //创建一个socket  
    $socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)or die("cannot create socket\n");  
    $conn=socket_connect($socket,$host,$port) or die("cannot connect server\n");  
    if($conn) { 
    	$checking = (8 + $name + $opercode) & 0xff;
	    $req = pack("C*", 0xAA, 8, $name, $opercode, 0x00, 0x00, $checking, 0x55);; 
	    socket_write($socket,$req) or die("cannot write data\n");  
	    $buffer=socket_read($socket,8);  
	    if($buffer){
	    	// TODO: checking value
	    	$rsp = unpack('C*', $buffer);
	    	if (sizeof($rsp) >= 6) {
	    		// Big indian
	    		$value = $rsp[5] << 8 | $rsp[6];
				echo '<h2> 读数：' . $value . "</h2>"; 
	    	} else {
	    		echo 'invalid data format!';
	    	}
	        
	    } else {
	    	echo "<h2>server internal error</h2>";
	    }            
	    socket_close($socket);
	}
?>